package com.community.pojo.entity;

import lombok.Data;

/**
 * @author zxd
 * @date 2025/7/17
 */
@Data
public class Result<T> {

    //状态码
    private Integer code;

    //提示信息
    private String msg;

    //携带的数据
    private T data;

    //总记录数
    private Long count;


    /**
     * 构建分页结果
     * @param obj
     * @param count
     * @return
     */
    public static Result buildSuccess(Object obj, Long count){
        Result result=new Result();
        result.setData(obj);
        result.setCount(count);
        result.setCode(0);
        result.setMsg("请求成功");
        return result;
    }

    /**
     * 构建不带总记录数的返回
     * @param obj
     * @return
     */
    public static Result buildSuccess(Object obj){
        Result result=new Result();
        result.setData(obj);
        result.setCode(0);
        result.setMsg("请求成功");
        return result;
    }

    /**
     * 构建不带数据的返回
     * @return
     */
    public static Result buildSuccess(){
        Result result=new Result();
        result.setCode(0);
        result.setMsg("请求成功");
        return result;
    }

    /**
     * 构建失败
     * @param code
     * @param msg
     * @return
     */
    public static Result buildFail(Integer code,String msg){
        Result result=new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


}